// 云函数入口文件
const cloud = require('wx-server-sdk')
const md5 =require("md5");

process.env.TZ ='Asia/Shanghai'
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
// 云函数入口函数

const db = cloud.database()
const _ = db.command

exports.main = async (event, context) => {
  console.log(event);

  const wxContext = cloud.getWXContext()


  let _openid = wxContext.OPENID;

  try{
    let _id = md5(_openid);
    await db.collection('users').doc(_id).update({
      // data 字段表示需新增的 JSON 数据
      data: {
        userInfo: event.userInfo,
        ...event.userInfo,
        updateTime: Date.now()
      }
    })

  }catch(err){

  }
  
  


}